package dk.eclipse.android.badassapp.sensor.orientation;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class OrientationView extends View {
	private Context context = null;
	private AttributeSet attrs = null;
	
	private float azimuth;
	private Paint mPaint = new Paint();
	private Path mPath = new Path();

	public OrientationView(Context context) {
		super(context);
		create();
	}

	public OrientationView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		this.attrs = attrs;
		create();
	}
	
	public OrientationView(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		create();
	}


	@Override
	protected void onDraw(Canvas canvas) {
		Paint paint = mPaint;

		canvas.drawColor(Color.BLACK);

		paint.setAntiAlias(true);
		paint.setColor(Color.BLUE);
		paint.setStyle(Paint.Style.FILL);

		int w = getWidth();
		int h = getHeight();
		int cx = w / 2;
		int cy = h / 2;

		canvas.translate(cx, cy);
		canvas.rotate(-azimuth);
		canvas.drawPath(mPath, mPaint);
	}

	/**
	 * @return the azimuth
	 */
	public float getAzimuth() {
		return azimuth;
	}

	/**
	 * @param azimuth
	 *            the azimuth to set
	 */
	public void setAzimuth(float azimuth) {
		this.azimuth = azimuth;
	}

	private void create() {
		// Construct a wedge-shaped path
		mPath.moveTo(0, -50);
		mPath.lineTo(-20, 60);
		mPath.lineTo(0, 50);
		mPath.lineTo(20, 60);
		mPath.close();
	}
}
